package com.wondersgroup.core.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.wondersgroup.core.mapper.PlatformMapper;
import com.wondersgroup.core.model.Platform;

@Service
public class PlatformService {
	@Autowired
	private PlatformMapper platformMapper;

    
	/**
	 * 查询所有追溯平台
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public List<Platform> findAll(int pageNum,int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<Platform> platforms = platformMapper.findAll();
		return platforms;
	}

	/**
	 * 根据id查询追溯平台
	 * @param id
	 * @return Platform
	 */
	public Platform findById(int id) {
		Platform platform = platformMapper.selectByPrimaryKey(id);
		return platform;
	}

	/**
	 * 根据id删除追溯平台
	 * @param id
	 * @return
	 */
	public int deleteById(int id) {
		return platformMapper.deleteById(id);
	}
   
	/**
	 * 增加追溯平台
	 * @param platform
	 * @return
	 */
	public int insert(Platform platform) {
		platform.setCreateDate(new Date());
    	platform.setLastModifiedDate(new Date());
		return platformMapper.add(platform);
	}

	/**
	 * 更新追溯平台
	 * @param platform
	 * @return
	 */
	public int update(Platform platform) {
		Platform p=platformMapper.selectByPrimaryKey(platform.getId());
		platform.setCreateDate(p.getCreateDate());
    	platform.setLastModifiedDate(new Date());
		return platformMapper.update(platform);
	}
	
	/**
	 * 获取已接入的追溯平台的个数
	 * @return
	 */
	public long  getCountOfJoinedPlatform() {
		return platformMapper.getCountOfJoinedPlatform();
	}

}
